home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / sun3.md / machMigrate.c < prev    next >
C/C++ Source or Header  |  1989-10-30  |  8KB  |  277 lines

  1. /* 
  2.  * machMigrate.c --
  3.  *
  4.  *         Machine dependent code to support process migration.  These routines
  5.  *         encapsulate and deencapsulate the machine-dependent state of a
  6.  *    process and set up the state of the process on its new machine.
  7.  *
  8.  * Copyright 1988 Regents of the University of California
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifndef lint
  19. static char rcsid[] = "$Header: /sprite/src/kernel/mach/sun3.md/RCS/machMigrate.c,v 9.1 89/10/30 20:49:02 rab Exp $ SPRITE (Berkeley)";
  20. #endif /* not lint */
  21.  
  22. #include "sprite.h"
  23. #include "machConst.h"
  24. #include "machInt.h"
  25. #include "mach.h"
  26. #include "machMon.h"
  27. #include "sched.h"
  28. #include "procMigrate.h"
  29.  
  30. /*
  31.  * The information that is transferred between two machines.
  32.  */
  33. typedef struct {
  34.     Mach_UserState userState;        /* The contiguous machine-dependent
  35.                      * user state. */
  36.     int    pc;                /* PC at which to resume execution. */
  37. } MigratedState;
  38.  
  39.  
  40. /*
  41.  * ----------------------------------------------------------------------------
  42.  *
  43.  * Mach_EncapState --
  44.  *
  45.  *    Copy the machine-dependent information for a process into
  46.  *    a buffer.  The buffer passed to the routine must contain space for
  47.  *    a MigratedState structure, the size of which is accessible via 
  48.  *    another procedure.  
  49.  *
  50.  * Results:
  51.  *      SUCCESS.
  52.  *    The buffer is filled with the user state and PC of the process.
  53.  *
  54.  * Side effects:
  55.  *    None.
  56.  *
  57.  * ----------------------------------------------------------------------------
  58.  */
  59. /* ARGSUSED */
  60. ReturnStatus
  61. Mach_EncapState(procPtr, hostID, infoPtr, buffer)
  62.     register Proc_ControlBlock     *procPtr;  /* The process being migrated */
  63.     int hostID;                   /* host to which it migrates */
  64.     Proc_EncapInfo *infoPtr;           /* area w/ information about
  65.                         * encapsulated state */
  66.     Address buffer;               /* Pointer to allocated buffer */
  67. {
  68.     Mach_State *machStatePtr = procPtr->machStatePtr;
  69.     MigratedState *migPtr = (MigratedState *) buffer;
  70.  
  71.     bcopy((Address) &machStatePtr->userState, (Address) &migPtr->userState,
  72.         sizeof(Mach_UserState));
  73.     migPtr->pc = machStatePtr->userState.excStackPtr->pc;
  74.     return(SUCCESS);
  75. }    
  76.     
  77.  
  78. /*
  79.  * ----------------------------------------------------------------------------
  80.  *
  81.  * Mach_DeencapState --
  82.  *
  83.  *    Copy the machine-dependent information for a process from
  84.  *    a buffer.  The buffer passed to the routine must contain
  85.  *    a MigratedState structure created by Mach_EncapState on the
  86.  *    machine starting a migration.  
  87.  *
  88.  * Results:
  89.  *    The user state and PC of the process are initialized from the
  90.  *    encapsulated information, and the other standard process
  91.  *    initialization operations are performed (by the general initialization
  92.  *    procedure).  The status from that procedure is returned.
  93.  *
  94.  * Side effects:
  95.  *    None.
  96.  *
  97.  * ----------------------------------------------------------------------------
  98.  */
  99. /* ARGSUSED */
  100. ReturnStatus
  101. Mach_DeencapState(procPtr, infoPtr, buffer)
  102.     register Proc_ControlBlock     *procPtr; /* The process being migrated */
  103.     Proc_EncapInfo *infoPtr;          /* information about the buffer */
  104.     Address buffer;              /* buffer containing data */
  105. {
  106.     MigratedState *migPtr = (MigratedState *) buffer;
  107.     ReturnStatus status;
  108.  
  109.     if (infoPtr->size != sizeof(MigratedState)) {
  110.     if (proc_MigDebugLevel > 0) {
  111.         printf("Mach_DeencapState: warning: host %d tried to migrate",
  112.         procPtr->peerHostID);
  113.         printf(" onto this host with wrong structure size.");
  114.         printf("  Ours is %d, theirs is %d.\n",
  115.         sizeof(MigratedState), infoPtr->size);
  116.     }
  117.     return(PROC_MIGRATION_REFUSED);
  118.     }
  119.  
  120. #ifdef sun3
  121.     if (migPtr->userState.trapFpuState.version != 0) {
  122.     if (mach68881Present == FALSE) {
  123.         /*
  124.          *  This machine has no fpu, and this process needs one.
  125.          *  So we can't accept it.
  126.          */
  127.         printf("Mach_DeencapState: warning: host %d tried to migrate",
  128.         procPtr->peerHostID);
  129.         printf(" a process that uses the fpu.  This host has no fpu.\n");
  130.         return PROC_MIGRATION_REFUSED;
  131.     }
  132.     if (migPtr->userState.trapFpuState.state != MACH_68881_IDLE_STATE) {
  133.         printf("Mach_DeencapState: warning: host %d tried to migrate",
  134.         procPtr->peerHostID);
  135.         printf(" a process with a non-idle fpu onto this host.  ");
  136.         printf("The fpu was in state 0x%02x\n",
  137.         migPtr->userState.trapFpuState.state);
  138.         return PROC_MIGRATION_REFUSED;
  139.     }
  140.     if (migPtr->userState.trapFpuState.version != mach68881Version) {
  141.         /*
  142.          *  The sending host has a different version of the
  143.          *  mc68881 fpu.  The state frames are incompatible
  144.          *  between versions.  But since it is in idle state
  145.          *  we can just use a generic idle state frame, rather
  146.          *  than the one we were sent.
  147.          */
  148.         migPtr->userState.trapFpuState = mach68881IdleState;
  149.     }
  150.     }
  151. #endif
  152.  
  153.     /*
  154.      * Get rid of the process's old machine-dependent state if it exists.
  155.      */
  156.     if (procPtr->machStatePtr != (Mach_State *) NIL) {
  157.     Mach_FreeState(procPtr);
  158.     }
  159.  
  160.     /*
  161.      * This procedure relies on the fact that Mach_SetupNewState
  162.      * only looks at the Mach_UserState part of the Mach_State structure
  163.      * it is given.  Therefore, we can coerce the pointer to a Mach_State
  164.      * pointer and give it to Mach_UserState to get registers & such.
  165.      */
  166.  
  167.     status = Mach_SetupNewState(procPtr, (Mach_State *) &migPtr->userState,
  168.                 Proc_ResumeMigProc, (Address)migPtr->pc, TRUE);
  169.     return(status);
  170. }    
  171.     
  172.  
  173.  
  174. /*
  175.  * ----------------------------------------------------------------------------
  176.  *
  177.  * Mach_GetEncapSize --
  178.  *
  179.  *    Return the size of the encapsulated machine-dependent data.
  180.  *
  181.  * Results:
  182.  *    SUCCESS is returned directly; the size of the encapsulated state
  183.  *    is returned in infoPtr->size.
  184.  *
  185.  * Side effects:
  186.  *    None.
  187.  *
  188.  * ----------------------------------------------------------------------------
  189.  *
  190.  */
  191.  
  192. /* ARGSUSED */
  193. ReturnStatus
  194. Mach_GetEncapSize(procPtr, hostID, infoPtr)
  195.     Proc_ControlBlock *procPtr;            /* process being migrated */
  196.     int hostID;                    /* host to which it migrates */
  197.     Proc_EncapInfo *infoPtr;            /* area w/ information about
  198.                          * encapsulated state */
  199. {
  200.     infoPtr->size = sizeof(MigratedState);
  201.     return(SUCCESS);
  202. }
  203.  
  204.  
  205. /*
  206.  * ----------------------------------------------------------------------------
  207.  *
  208.  * Mach_CanMigrate --
  209.  *
  210.  *    Indicate whether a process's trapstack is in a form suitable for
  211.  *    starting a migration.
  212.  *
  213.  * Results:
  214.  *    TRUE if we can migrate using this trapstack, FALSE otherwise.
  215.  *
  216.  * Side effects:
  217.  *    None.
  218.  *
  219.  * ----------------------------------------------------------------------------
  220.  */
  221. Boolean
  222. Mach_CanMigrate(procPtr)
  223.     Proc_ControlBlock *procPtr;        /* pointer to process to check */
  224. {
  225.     Boolean okay;
  226.  
  227.     okay = TRUE;
  228.  
  229. #ifdef sun3
  230.     /*
  231.      *  If the floating point state is busy, that means that a
  232.      *  floating point instruction is suspended, waiting to be
  233.      *  restarted.  It cannot be restarted on a machine with another
  234.      *  version of the chip, since the microcode is incompatible between
  235.      *  revisions.  So we will delay the migration until the instruction
  236.      *  completes.
  237.      */
  238.     if (procPtr->machStatePtr->userState.trapFpuState.state >=
  239.         MACH_68881_BUSY_STATE) {
  240.     okay = FALSE;
  241.     }
  242. #endif
  243.  
  244.     if (proc_MigDebugLevel > 4) {
  245.     printf("Mach_CanMigrate called. PC %x, stackFormat %x, returning %d.\n",
  246.            procPtr->machStatePtr->userState.excStackPtr->pc, okay);
  247.     }
  248.     return(okay);
  249. }    
  250.  
  251.  
  252. /*
  253.  *----------------------------------------------------------------------
  254.  *
  255.  * Mach_GetLastSyscall --
  256.  *
  257.  *    Return the number of the last system call performed for the current
  258.  *    process.
  259.  *
  260.  * Results:
  261.  *    The system call number is returned.
  262.  *
  263.  * Side effects:
  264.  *    None.
  265.  *
  266.  *----------------------------------------------------------------------
  267.  */
  268.  
  269. int
  270. Mach_GetLastSyscall()
  271. {
  272.     Proc_ControlBlock *procPtr;        /* pointer to process to check */
  273.  
  274.     procPtr = Proc_GetCurrentProc();
  275.     return(procPtr->machStatePtr->userState.lastSysCall);
  276. }
  277.